package com.service.configration.imp;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.mapper.configration.DictionaryMapper;
import com.po.DictionaryInfo;
import com.service.configration.DictionaryService;
import com.util.UUIDGenerator;

@Service
public class DictionaryServiceImp implements DictionaryService {
	@Resource(name = "dictionaryMapper")
	private DictionaryMapper dictionaryMapper;

	@Override
	public List<DictionaryInfo> getDictionaryList(DictionaryInfo dictionaryInfo) {
		List<DictionaryInfo> list = dictionaryMapper.getDictionaryList(dictionaryInfo);
		return list;
	}

	@Override
	public int getDictionaryCount(DictionaryInfo dictionaryInfo) {
		int i = dictionaryMapper.getDictionaryCount(dictionaryInfo);
		return i;
	}

	@Override
	public DictionaryInfo addDictionary(DictionaryInfo dictionaryInfo) {
		
		dictionaryInfo.setId(UUIDGenerator.getUUID());
		int i = dictionaryMapper.addDictionary(dictionaryInfo);
		if (i == 1)
			return dictionaryInfo;
		else
			return null;
	}

	@Override
	public int updateDictionary(DictionaryInfo dictionaryInfo) {
		int i = dictionaryMapper.updateDictionary(dictionaryInfo);
		if(i>0)
			dictionaryMapper.updateInfoTagname(dictionaryInfo.getOldname(), dictionaryInfo.getName());
		return i;
	}

	@Override
	public int deleteDictionary(DictionaryInfo dictionaryInfo) {
		int i = dictionaryMapper.deleteDictionary(dictionaryInfo);
		return i;
	}

	@Override
	public int getDictionaryMax() {
		int i = dictionaryMapper.getDictionaryMax();
		return i;
	}

}
